package org.ctsi.rsds.api.rest;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;
import javax.ws.rs.core.UriInfo;

import org.ctsi.rsds.api.IResourceObjModel;
import org.ctsi.rsds.api.resource.ResourceObjResource;
import org.ctsi.rsds.api.rest.handler.ResourceObjResourceHandler;
import org.ctsi.rsds.base.rest.WebService;
import org.ctsi.rsds.base.rest.result.ObjectRESTResult;
import org.ctsi.rsds.pojo.ResourceObj;
import org.ctsi.rsds.service.ResourceObjService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ApiResponse;

//import com.wordnik.swagger.annotations.Api;
//import com.wordnik.swagger.annotations.ApiOperation;
//import com.wordnik.swagger.annotations.ApiResponse;
//import com.wordnik.swagger.annotations.ApiResponses;

@Api(value="/resourceobj", description="ResourceObjModel", position=0)
@Path("/resourceobj")
@Component
public class ResourceObjModel extends WebService implements IResourceObjModel {
    
	private final ResourceObjResourceHandler resourceObjResourceHandler = new ResourceObjResourceHandler();
    Logger logger = LoggerFactory.getLogger(ResourceObjModel.class);
    
    @Autowired
    @Qualifier("resourceObjService")
    private ResourceObjService resourceObjService;

    public ResourceObjModel(){}

    public ResourceObjModel(@Context UriInfo uriInfo, @Context HttpHeaders headers, @Context SecurityContext securityContext) {
        super(uriInfo, headers, securityContext);
    }

    @GET
    @Path("{id}")
    @Produces({MediaType.APPLICATION_JSON})
    @ApiOperation(value="findResObjByResObjId", notes="通过id来获取指定的资源信息")
    @ApiResponses(value={
    		@ApiResponse(code=400, message="Invalid id supplied"),
    		@ApiResponse(code=404, message="id not found")
    })
    public Response findResObjByResObjId(@PathParam("id") String id) {
       
    	ResourceObj resourceObj = resourceObjService.findResObjByResObjId(id);
        
    	ResourceObjResource resourceObjResource = resourceObjResourceHandler.convertFromResourceObj(resourceObj);

        return Response.ok(new ObjectRESTResult(200, "OK", resourceObjResource)).build();
    }
	
}
